#include <stdio.h>
#include "sdf.h"


int main() {
    HANDLE deviceHandle;
    LONG openResult, closeResult;

void *pdh;
    int ret;
    // 打开设备
    openResult = SDF_OpenDevice(&deviceHandle);
    if (openResult == 0) {
        printf("设备打开成功。\n");

    } else {
        printf("设备打开失败，错误代码: %ld\n", openResult);
    }
    
    // 测试生成1个字节的随机数
    unsigned char random1[1];
    ret = SDF_GenerateRandom(pdh, 1, random1);
    if (ret == SDR_OK) {
        printf("1-byte random number: %d\n", random1[0]);
    } else {
        printf("Error generating 1-byte random number!\n");
    }

    // 测试生成5个字节的随机数
    unsigned char random5[5];
    ret = SDF_GenerateRandom(pdh, 5, random5);
    if (ret == SDR_OK) {
        printf("5-byte random number: ");
        for (int i = 0; i < 5; i++) {
            printf("%d ", random5[i]);
        }
        printf("\n");
    } else {
        printf("Error generating 5-byte random number!\n");
    }

    // 测试生成20个字节的随机数
    unsigned char random20[20];
    ret = SDF_GenerateRandom(pdh, 20, random20);
    if (ret == SDR_OK) {
        printf("20-byte random number: ");
        for (int i = 0; i < 20; i++) {
            printf("%d ", random20[i]);
        }
        printf("\n");
    } else {
        printf("Error generating 20-byte random number!\n");
    }
    
    

        // 关闭设备
        closeResult = SDF_CloseDevice(deviceHandle);
        if (closeResult == 0) {
            printf("设备关闭成功。\n");
        } else {
            printf("设备关闭失败，错误代码: %ld\n", closeResult);
        }
    return 0;
}

